package com.jiuling.apis.controller;

import com.jswzc.framework.controller.BaseController;
import com.jswzc.pay.service.balanceService.BrandOrderServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by qziwm on 2017/6/8.
 */
@Controller
@RequestMapping("/api")
public class ApiController extends BaseController {
    @Autowired
    private BrandOrderServiceI brandOrderService;


    /**
     * 商户新增订单接口
     */
    @RequestMapping(value="/addOrder")
    public synchronized void addOrder(@RequestParam(value="json", required=true) String json, HttpServletResponse response){

        Map<String,Object> res = new HashMap<String, Object>();
        try {

            res=brandOrderService.addOrder(json);//处理用户久零贝

        } catch (Exception e) {
            res.put("flag", "1");
            res.put("msg","操作失败,参数错误");

        }
        writeJson(res,response);
    }
    /**
     * 获取订单
     */
    @RequestMapping(value="/getOrder")
    public synchronized void getOrder(@RequestParam(value="code", required=true) String code, HttpServletResponse response) throws Exception {
        Map<String,Object> res = new HashMap<String, Object>();

            res=brandOrderService.getOrder(code);

        writeJson(res,response);
    }
    /**
     * 完成订单
     */
    @RequestMapping(value="/finishOrder")
    public synchronized void finishOrder(@RequestParam(value="code", required=true) String code,@RequestParam(value="openId", required=true)String openId, HttpServletResponse response) throws Exception {
        Map<String,Object> res = new HashMap<String, Object>();

        res=brandOrderService.finishOrder(code,openId);

        writeJson(res,response);
    }
}
